package com.briup.ch11;

import java.io.*;

/**
 * @author yuxi
 * @version 1.0
 * @date 2025/10/16
 * @Description:
 */
public class Test12_Buffer {
    public static void main(String[] args) throws IOException {
        //缓冲字节流
        FileInputStream fis=new FileInputStream("1.jpg");
        FileOutputStream fos=new FileOutputStream("3.jpg");
        BufferedInputStream bis=new BufferedInputStream(fis);//直接new也行,包装流关闭时，不仅关闭自己的流，还会关闭被包装的节点流
        BufferedOutputStream bos=new BufferedOutputStream(fos);//直接new也行,包装流关闭时，不仅关闭自己的流，还会关闭被包装的节点流

        byte[] buffer=new byte[1024];
        int len=0;
        while((len=bis.read(buffer))!=-1){
            bos.write(buffer,0,len);
            bos.flush();
        }
        bos.close();
        bis.close();
        fos.close();
        fis.close();
        //缓冲字符流
        BufferedReader br=new BufferedReader(new FileReader("test.txt"));
        BufferedWriter bw=new BufferedWriter(new FileWriter("test3.txt"));
        String line=null;
        while((line=br.readLine())!=null){
            bw.write(line);
            bw.newLine();
            bw.flush();
        }
        //关闭流时，先关闭包装流，再关闭被包装的节点流
        bw.close();
        br.close();
    }
}
